package org.shindou09.easytagforpage.view.jsp.impl;

import org.shindou09.easytagforpage.Page;
import org.shindou09.easytagforpage.view.jsp.JspPageView;

public class DefaultJspPageViewImpl implements JspPageView{

	public String createJsp(Page page, String pageUrl) {
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer
				.append("<table border='0' align='center' cellpadding='1' cellspacing='0'>"
						+ "<tr><td height='27' align='center' valign='bottom'>共<font color='FF0000'>"
						+ page.getTotalRows()
						+ "</font>条信息&nbsp;&nbsp;每页<font color='FF0000'>"
						+ page.getPageSize()
						+ "</font>条&nbsp;&nbsp;共<font color='FF0000'>"
						+ page.getTotalPages()
						+ "</font>页&nbsp;&nbsp;当前为第<font color='FF0000'>"
						+ page.getCurrentPage()
						+ "</font>页&nbsp;&nbsp;选择第<select name='selectname'  onChange='zhuan(this.value)'>");
		for(int i=1;i<=page.getTotalPages();i++){
			if(page.getCurrentPage()==i)
				stringBuffer.append("<option value='"+i+"' selected=''selected'>"+i+"</option>");
			else
				stringBuffer.append("<option value='"+i+"'>"+i+"</option>");
		}
		stringBuffer
				.append("</select>页</td></tr>");
		stringBuffer.append("<script>function zhuan(value){window.location.href='"+pageUrl+(pageUrl.contains("?")==true ? "&" : "?")+"page='+value;}</script>");
		stringBuffer.append("<tr><td height='24' align='center' valign='bottom'>");

		stringBuffer.append("<a href='"+pageUrl+(pageUrl.contains("?")==true ? "&" : "?")+"page="+page.getCurrentPage()+"&action=first'>第一页</a>&nbsp;&nbsp;");
		if(page.isHasPreviousPage())
			stringBuffer.append("<a href='"+pageUrl+(pageUrl.contains("?")==true ? "&" : "?")+"page="+page.getCurrentPage()+"&action=previous'>上一页</a>&nbsp;&nbsp;");
		else
			stringBuffer.append("上一页&nbsp;&nbsp;");
		if(page.isHasNextPage())
			stringBuffer.append("<a href='"+pageUrl+(pageUrl.contains("?")==true ? "&" : "?")+"page="+page.getCurrentPage()+"&action=next'>下一页</a>&nbsp;&nbsp;");
		else
			stringBuffer.append("下一页&nbsp;&nbsp;");
		stringBuffer.append("<a href='"+pageUrl+(pageUrl.contains("?")==true ? "&" : "?")+"page="+page.getCurrentPage()+"&action=last'>最后一页</a>");
		stringBuffer.append("</td></tr></table>");
		return stringBuffer.toString();
	}

}
